﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using ECare.BUS;
using ECare.BUS.Data;
using ECare.BUS.Workers;
using ECare.Client.templates;

namespace ECare.Client.frms
{
    public partial class frmOutFormReadonly : frmInfo
    {
        public frmOutFormReadonly()
        {
            InitializeComponent();

            this.Load += frmOutFormReadonly_Load;
        }

        void frmOutFormReadonly_Load(object sender, EventArgs e)
        {
            //throw new NotImplementedException();
           
            this.LoadInformation();
        }

        public DataTable source { get; set; }

        private void LoadInformation()
        {
            if (this.entity != null)
            {
                var currentout = this.entity as ResourceOutInfo;

                this.lblSheetNo.Text = currentout.resource_out_sheet_no;
                this.lblMaterial.Text = ResourcesHelper.GetResourceName(currentout.resource_id.Value);
                this.lblNumbers.Text = currentout.resource_numbers.Value.ToString();
                this.lblUsers.Text = UserInfoHelper.GetUserNameById(currentout.resource_get_by.Value);
                this.lblGetDate.Text = currentout.resource_get_time.Value.ToShortDateString();
                source = ResourceOutHelper.GetOutDetails(currentout.resource_out_id);
                this.eGridView1.DataSource = source;

                //if (source.Rows.Count > 0)
                //{
                //    this.btnSave.Visible = true;
                //}
                //else
                //{
                //    this.btnSave.Visible = false;
                //}

            }
        }

        public event EntitySavedHandler Deactived;

        private void btnSave_Click(object sender, EventArgs e)
        {
            if (MessageBox.Show("是否删除此出库单?", "信息提示", MessageBoxButtons.YesNo, MessageBoxIcon.Information) ==
                DialogResult.No)
                return;

            var currentout = this.entity as ResourceOutInfo;
            SupplyInfoHelper.DeactiveStorageOut(currentout.resource_out_id);

            if (this.Deactived != null)
            {
                this.Deactived(this.entity);
            }
            this.Close();

        }
    }
}
